﻿using Microsoft.AspNetCore.SignalR;
using System.Security.Claims;

namespace Identity_MVC.SignalR
{
    /// <summary>
    /// 客户端Js的位置在wwwroot>js>HubChat.js中
    /// </summary>
    public class MyHub:Hub
    {
        public Task SendMsg(string name,string msg) 
        {
            string connId = this.Context.ConnectionId; // 拿到连接到该服务的Id；
            string sendmssg = $"Id:{connId},创建时间：{DateTime.UtcNow }，内容：{msg}";
            // return Clients.All.SendAsync("ReceivePublicMessage",name,sendmssg);  // 分发给所有客户端
            //return Clients.Client(connId).SendAsync("ReceivePublicMessage", name, sendmssg); //指定某个客户端发送消息
            return Clients.Others.SendAsync("ReceivePublicMessage", name, sendmssg); //分发给其它客户端

          
        }
    }
}
